///#begin en
//
//  Copyright (c) 2016 MyCamCloud. All rights reserved.
//
///#end

#import <mach/mach_time.h>

@class TreeListItem;
@class NetworkSpeed;
@class MP4Maker;
@class MEAudioPlayer;
@class MEAudioRecorder;
@class HKSRecFile;
#import "HKPlayerDelegate.h"
///#begin zh-cn
/**
 *  @class      HKSDeviceClient
 *  @brief      摄像头相关操作的顶级接口，所有摄像头相关功能都由此类进行提供
 */
///#end
///#begin en
/**
 *  @class      HKSServerClient
 *  @brief      Camera function interface class, all camera functions performed by such offers
 */
///#end
@interface HKSDeviceClient : NSObject{
    
    /** @brief  连接类型，HKS_NPC_D_MON_CLIENT_MODE_*  */
    void            *_videoDecoder;
    BOOL            _isPlayerPause;
    BOOL            _isNoCanPlaying;
    BOOL            _pause;
    BOOL            _isIFrame;
    void            *_pCamera;
    void            *_pServerClient;
    void            *_parser;
    NSThread        *_decodeThread;
    NetworkSpeed    *_networkSpeed;
    MP4Maker        *_mp4Maker;
    NSString        *_recordPath;
    
    int             _nDynamicFPS;
    int             _videoWidth;
	int             _videoHeight;
    int             _frameRate;
    int             _nDecodeIndex;
    int             _nAllFrameRate;
    int             _iRealplayOriFrameRate;
    MEAudioPlayer   *_auPlayer;
    MEAudioRecorder *_auRecorder;
    mach_timebase_info_data_t _deviceClientInfo;
    HKSRecFile      *_recFile;
    int             _networkTraffic;
    
    UIImage         *_downImage;
    
    NSCondition         *_connLock;
    NSCondition         *_recLock;
    BOOL                _isDowningFile;
    BOOL                _isPlaying;
    
    int                 _iAudioCodecId;
    int                 _clearFrameNumber;
    BOOL                _isSearching;
    NSTimeInterval      _frameStartTime;
    
    int                 _iVideoCodecId;
    
    BOOL                _isBackplay;
    
    int                 _iControlSpeed;
    
}

@property(nonatomic, copy) NSString             *deviceID;

@property(nonatomic, copy) NSString             *deviceUMID;
@property(nonatomic, copy) NSString             *deviceAddress;
@property(nonatomic, copy) NSString             *deviceUserID;
@property(nonatomic, copy) NSString             *devicePassword;
@property(nonatomic, assign) int                deviceChannel;
@property(nonatomic, assign) int                devicePort;
@property(nonatomic, assign) int                deviceStream;
/** @brief  设备协议ID，缺省：HKS_NPC_D_MON_VENDOR_ID_UMSP */
@property(nonatomic, assign) HKS_NPC_D_MON_VENDOR_ID        deviceVendor;
@property(nonatomic, assign) HKS_NPC_D_MON_DEV_CONN_MODE    deviceConnMode;
@property(nonatomic, assign) HKS_NPC_D_MON_CLIENT_MODE      connType;

/** @brief  设备标识，连接设备之前设置才有效 缺省：HKS_NPC_D_MON_CLIENT_FLAG_UMSP */
@property(nonatomic, assign) HKS_NPC_D_MON_CLIENT_FLAG      clientFlag;

@property(nonatomic, copy) NSString             *serverIP;
@property(nonatomic, assign) int                serverPort;

@property(nonatomic, retain) TreeListItem       *currentItem;
/** @brief  视频显示试图的背景颜色，不支持透明 */
@property(nonatomic, retain) UIColor            *displayViewColor;

@property(nonatomic, assign) id<HKPlayerDelegate>   delegate;

/** @brief  当前录像是否出现错误中断 */
@property(nonatomic, assign) BOOL               recordError;

/** @brief  是否开启录像,缺省:NO */
@property(nonatomic, assign) BOOL               recordEnabled;

/** @brief  视频显示视图是否隐藏,缺省:NO */
@property(nonatomic, assign) BOOL               hiddenDisplayView;

/** @brief  是否开启音频,缺省:NO */
@property(nonatomic, assign) BOOL               audioEnabled;

/** @brief  是否平铺播放试图,缺省:YES */
@property(nonatomic, assign) BOOL               fullScreenEnabled;

/** @brief  是否使用平滑,缺省:NO */
@property(nonatomic, assign) BOOL               smoothEnabled;

/** @brief  本地录像状态,缺省:0，0：停止录像、1：正在录像、2：正在转码成标准mp4文件过程中 */
@property(nonatomic, assign) int                localRECStatus;

/** @brief  本地录像录制的最大时长（单位:秒）,缺省:0，无限制 */
@property(nonatomic, assign) int                localRECMaxTime;

/** @brief  本地录像的每个文件的最大时长，最大限制的时间，将会换一个新的文件录制（单位:秒）,缺省:0，无限制 */
@property(nonatomic, assign) int                localRECMaxFileTime;

/** @brief  是否在本地录像文件后面增加帧率,缺省:NO */
@property(nonatomic, assign) BOOL               localRECFilePathFPS;

/** @brief  是否在本地录像的时候写入音频,缺省:YES */
@property(nonatomic, assign) BOOL               localRECWirteAudeioEnabled;

/** @brief  是否开启本地mp4平滑处理，缺省:NO */
@property(nonatomic, assign) BOOL                   localMP4SmoothEnabled;

/** @brief  是否开启解码I帧模式,缺省:NO */
@property(nonatomic, assign) BOOL               decodingIFrameEnabled;

/** @brief  按时间播放远程回放，缺省:NO */
@property(nonatomic, assign) BOOL               timePlayRECEnabled;

/** @brief  播放状态 */
@property(nonatomic, assign) HKSDevicePlayStatus    playerState;
/** @brief  下载文件状态 */
@property(nonatomic, assign) HKSDevicePlayStatus    downFileState;
/** @brief  对讲状态 */
@property(nonatomic, assign) int                    talkState;

/** @brief  实时播放的平均帧率 */
@property(nonatomic, assign, readonly) int          videoFrameRate;

/** @brief  是否播放的平均码流 */
@property(nonatomic, assign, readonly) float        videoNetworkSpeed;

/** @brief  播放画面视图 */
@property(nonatomic, retain) UIView                 *view;

/** @brief  连接失败并且出现密码错误的时候是否自动修改加密方式进行重练，缺省:NO */
@property(nonatomic, assign) BOOL                   connFailModifyEncryptionReconnection;



/** @brief  解码类型ID，缺省:-1，根据设备传输类型解码,自动:-1,h264:0,mpeg4:1,mjpg:2,jpg:3,h265:4 */
@property(nonatomic, assign) int                    iVideoDecodeTypeId;


/**
 *  @brief      当前播放使用网络流量
 */
- (int)networkTraffic;

/**
 *  @brief      服务器句柄
 */
- (void *)serverClient;

/**
 *  @brief      开始播放摄像头
 */
- (void)start;
- (void)startAtConnParam:(NSString *)serverIP
              serverPort:(int)serverPort
              deviceUMID:(NSString *)deviceUMID
            deviceUserID:(NSString *)deviceUserID
          devicePassword:(NSString *)devicePassword
           deviceChannel:(int)deviceChannel
            deviceStream:(int)deviceStream
            deviceVendor:(int)deviceVendor;

/**
 *  @brief      停止播放摄像头
 *
 *  @param[in]  block[BOOL]:阻塞线程控制，YES：阻塞，NO：不阻塞
 */
- (void)stop:(BOOL)block;

/**
 *  @brief      停止播放摄像头
 *  @param[in]  block[BOOL]:阻塞线程控制，YES：阻塞，NO：不阻塞
 *  @param[in]  theExit[BOOL]:是否真正退出，YES：等待状态非HKS_NPC_D_MON_DEV_PLAY_STATUS_CONNECT_SERVER的时候，执行停止命定，NO：如果状态为HKS_NPC_D_MON_DEV_PLAY_STATUS_CONNECT_SERVER，将不会执行停止命定
 */
- (void)stop:(BOOL)block exit:(BOOL)theExit;

/**
 *  @brief      停止播放摄像头
 *  @param[in]  block[BOOL]:阻塞线程控制，YES：阻塞，NO：不阻塞
 *  @param[in]  theExit[BOOL]:是否真正退出，YES：等待状态非HKS_NPC_D_MON_DEV_PLAY_STATUS_CONNECT_SERVER的时候，执行停止命定，NO：如果状态为HKS_NPC_D_MON_DEV_PLAY_STATUS_CONNECT_SERVER，将不会执行停止命定
 *  @param[in]  aClearView[BOOL]:是否清除最后一帧图像
 */
- (void)stop:(BOOL)block exit:(BOOL)theExit clearView:(BOOL)aClearView;

/**
 *  @brief      重置音频模块
 */
- (void)resetAudio;

/** @brief  获取当前视频的编码ID,需要在状态为播放中的时候，该接口才有效 */
- (HKS_NPC_D_MON_CODEC_ID)videoCodecId;

/** @brief  播放状态 */
- (HKSDevicePlayStatus)playerState;

- (HKS_NPC_D_MON_DEV_CONN_TYPE)deviceConnNetworkMode;

- (void)setMaxRecordTime:(int)aMaxRecordTime IOS_VERSION_DEPRECATED("该接口已过时,请使用localRECMaxTime");

@end
